package com.ufo.mail.mailproducts.controller;

import java.util.Arrays;
import java.util.Map;

import com.ufo.mail.mailproducts.entity.BrandEntity;
import com.ufo.mail.mailproducts.feign.CouponFeignTest;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.ufo.mail.mailproducts.entity.AttrAttrgroupRelationEntity;
import com.ufo.mail.mailproducts.service.AttrAttrgroupRelationService;
import com.ufo.common.utils.PageUtils;
import com.ufo.common.utils.R;



/**
 * 属性&属性分组关联
 *
 * @author ufo
 * @email 2575829997@gmail.com
 * @date 2020-09-12 15:35:12
 */
@RefreshScope
@RestController
@RequestMapping("mailproducts/attrattrgrouprelation")
public class AttrAttrgroupRelationController {
    @Autowired
    private AttrAttrgroupRelationService attrAttrgroupRelationService;
    @Autowired
    CouponFeignTest couponFeignTest;
    /**
     * 服务调用测试
     */
    @RequestMapping("/listt")
    public R listt(@RequestParam Map<String, Object> params){
        BrandEntity brandEntity=new BrandEntity();
        brandEntity.setName("dwcbiweicwe");
         R coupontest=couponFeignTest.membercoupons();
         return R.ok().put("wedewfewdfewew",coupontest.get("coupon")).put("wedwedwe",brandEntity.getName());

    }


    /**
     * 配置文件读取测试
     */
    @Value("${cuser.name}")
    private String name;
    @Value("${cuser.age}")
    private String age;


    @RequestMapping("/listt2")
    public R listt2(@RequestParam Map<String, Object> params){

        return R.ok().put("wedewfewdfewew",name).put("wedwedwe",age);

    }
    /**
     * 列表
     */
    @RequestMapping("/list")
    public R list(@RequestParam Map<String, Object> params){
        PageUtils page = attrAttrgroupRelationService.queryPage(params);

        return R.ok().put("page", page);
    }


    /**
     * 信息
     */
    @RequestMapping("/info/{id}")
    public R info(@PathVariable("id") Long id){
		AttrAttrgroupRelationEntity attrAttrgroupRelation = attrAttrgroupRelationService.getById(id);

        return R.ok().put("attrAttrgroupRelation", attrAttrgroupRelation);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    public R save(@RequestBody AttrAttrgroupRelationEntity attrAttrgroupRelation){
		attrAttrgroupRelationService.save(attrAttrgroupRelation);

        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    public R update(@RequestBody AttrAttrgroupRelationEntity attrAttrgroupRelation){
		attrAttrgroupRelationService.updateById(attrAttrgroupRelation);

        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    public R delete(@RequestBody Long[] ids){
		attrAttrgroupRelationService.removeByIds(Arrays.asList(ids));

        return R.ok();
    }

}
